/*
* berton
*/
package com.pitop.supplier.ctrl;

import com.alibaba.fastjson.JSON;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;
import springfox.documentation.annotations.ApiIgnore;
import javax.annotation.Resource;
import java.util.List;
import java.util.HashMap;

import com.pitop.core.entity.BeanRet;
import com.pitop.core.entity.Page;
import com.pitop.core.tools.redis.RedisUtils;
import com.pitop.supplier.entity.SupplierCategory;
import com.pitop.supplier.service.SupplierCategorySV;

/**
* 供应商类型 控制器
*
* @author berton
*/
@RestController
@RequestMapping("/supplierCategory")
@Slf4j
@Api(value = "供应商类型控制器", description = "供应商类型控制器")
public class SupplierCategoryCtrl {

    @Resource
    protected RedisUtils redisUtils;

    @Resource
    private SupplierCategorySV supplierCategorySV;

    /**
    * 查询SupplierCategory一个详情信息
    * @param id 
    * @param code 类型编码
    * @return BeanRet
    */
    @ApiOperation(value = "查询SupplierCategory一个详情信息", notes = "查询SupplierCategory一个详情信息")
    @ApiImplicitParams({
        @ApiImplicitParam(name = "id", value = "",dataType = "java.lang.Long", paramType = "query"),
        @ApiImplicitParam(name = "code", value = "类型编码",dataType = "java.lang.String", paramType = "query")
    })
    @GetMapping(value = "/load")
    @ResponseBody
    public SupplierCategory load(java.lang.Long id,java.lang.String code) {
        if(id==null){
        return null;
        }
        if(code==null){
        return null;
        }
        SupplierCategory supplierCategory = supplierCategorySV.load(id,code);
        log.info(JSON.toJSONString(supplierCategory));
        return supplierCategory;
    }


    /**
    * 根据条件id查询SupplierCategory一个详情信息
    *
    * @param id 
    * @return BeanRet
    */
    @ApiOperation(value = "查询SupplierCategory一个详情信息", notes = "查询SupplierCategory一个详情信息")
    @ApiImplicitParams({
       @ApiImplicitParam(name = "id", value = "",dataType = "java.lang.Long", paramType = "path")
    })
    @GetMapping(value = "/load/id/{id}")
    @ResponseBody
    public SupplierCategory loadById(@PathVariable java.lang.Long id) {
        if(id==null){
           return null;
        }
        SupplierCategory supplierCategory = supplierCategorySV.loadById(id);
        log.info(JSON.toJSONString(supplierCategory));
        return supplierCategory;
    }
    /**
    * 根据条件code查询SupplierCategory一个详情信息
    *
    * @param code 类型编码
    * @return BeanRet
    */
    @ApiOperation(value = "查询SupplierCategory一个详情信息", notes = "查询SupplierCategory一个详情信息")
    @ApiImplicitParams({
       @ApiImplicitParam(name = "code", value = "类型编码",dataType = "java.lang.String", paramType = "path")
    })
    @GetMapping(value = "/load/code/{code}")
    @ResponseBody
    public SupplierCategory loadByCode(@PathVariable java.lang.String code) {
        if(code==null){
           return null;
        }
        SupplierCategory supplierCategory = supplierCategorySV.loadByCode(code);
        log.info(JSON.toJSONString(supplierCategory));
        return supplierCategory;
    }


    /**
    * 查询SupplierCategory信息集合
    *
    * @return 分页对象
    */
    @ApiOperation(value = "查询SupplierCategory信息集合", notes = "查询SupplierCategory信息集合")
    @ApiImplicitParams({
    @ApiImplicitParam(name = "curPage", value = "当前页", required = true, paramType = "query"),
    @ApiImplicitParam(name = "pageSize", value = "分页大小", required = true, paramType = "query"),
    })
    @PostMapping(value = "/list")
    @ResponseBody
    public List<SupplierCategory> list(@RequestBody @ApiIgnore SupplierCategory supplierCategory,Integer curPage,Integer pageSize) {
        Page<SupplierCategory> page=new Page<SupplierCategory>(pageSize,curPage);
        List<SupplierCategory> supplierCategorys = supplierCategorySV.list(supplierCategory,page.genRowStart(),page.getPageSize());
        int total = supplierCategorySV.count(supplierCategory);
        page.setTotalRow(total);
        log.info(JSON.toJSONString(page));
        return supplierCategorys;
    }


    /**
    * 查询SupplierCategory信息集合
    *
    * @return 分页对象
    */
    @ApiOperation(value = "查询SupplierCategory信息集合", notes = "查询SupplierCategory信息集合")
    @ApiImplicitParams({
    @ApiImplicitParam(name = "curPage", value = "当前页", required = true, paramType = "query"),
    @ApiImplicitParam(name = "pageSize", value = "分页大小", required = true, paramType = "query"),
    @ApiImplicitParam(name = "id", value = "", paramType = "query"),
    @ApiImplicitParam(name = "code", value = "类型编码", paramType = "query")
    })
    @GetMapping(value = "/list/by")
    @ResponseBody
    public List<SupplierCategory> listByPk(java.lang.Long id,java.lang.String code,Integer curPage,Integer pageSize) {
        Page<SupplierCategory> page=new Page<SupplierCategory>(pageSize,curPage);
        List<SupplierCategory> supplierCategorys = supplierCategorySV.list(id,code, page.genRowStart(),page.getPageSize());
        int total = supplierCategorySV.count(id,code);
        page.setTotalRow(total);
        log.info(JSON.toJSONString(page));
        return supplierCategorys;
    }

    /**
    * 统计SupplierCategory信息数量根据主键
    *
    * @return 总条数
    */
    @ApiOperation(value = " 统计SupplierCategory信息数量根据主键", notes = " 统计SupplierCategory信息数量根据主键")
    @ApiImplicitParams({
    @ApiImplicitParam(name = "id", value = "", paramType = "query"),
    @ApiImplicitParam(name = "code", value = "类型编码", paramType = "query")
    })
    @GetMapping(value = "/count/by")
    @ResponseBody
    public Integer count(java.lang.Long id,java.lang.String code) {
        return supplierCategorySV.count(id,code);
    }

    /**
    * 统计SupplierCategory信息数量
    *
    * @return 总条数
    */
    @ApiOperation(value = "统计SupplierCategory信息数量", notes = "统计SupplierCategory信息数量")
    @ApiImplicitParams({
    @ApiImplicitParam(name = "id", value = "", paramType = "query"),
    @ApiImplicitParam(name = "code", value = "类型编码", paramType = "query"),
    @ApiImplicitParam(name = "name", value = "类型", paramType = "query")
    })
    @PostMapping(value = "/count")
    @ResponseBody
    public Integer count(@RequestBody SupplierCategory supplierCategory) {
        if(supplierCategory==null){
            return supplierCategorySV.count(new HashMap());
        }else{
            return supplierCategorySV.count(supplierCategory);
        }
    }



    /**
    * 创建SupplierCategory
    *
    * @return BeanRet
    */
    @ApiOperation(value = "创建SupplierCategory", notes = "创建SupplierCategory")
    @ApiImplicitParams({
        @ApiImplicitParam(name = "name", value = "类型", paramType = "query")
    })
    @PostMapping("/build")
    @ResponseBody
    public SupplierCategory build(@RequestBody @ApiIgnore SupplierCategory supplierCategory) {
        supplierCategorySV.save(supplierCategory);
        return supplierCategory;
    }


    /**
    * 修改SupplierCategory
    *
    * @return BeanRet
    */
    @ApiOperation(value = "修改SupplierCategory", notes = "修改SupplierCategory")
    @ApiImplicitParams({
        @ApiImplicitParam(name = "id", value = "", paramType = "query"),
        @ApiImplicitParam(name = "code", value = "类型编码", paramType = "query"),
        @ApiImplicitParam(name = "name", value = "类型", paramType = "query")
    })
    @PutMapping("/modify")
    @ResponseBody
    public SupplierCategory modify(@ApiIgnore SupplierCategory supplierCategory) {
        supplierCategorySV.modify(supplierCategory);
        return supplierCategory;
    }

    /**
    * 删除SupplierCategory
    *
    * @return BeanRet
    */
    @ApiOperation(value = "删除SupplierCategory", notes = "删除SupplierCategory")
    @ApiImplicitParams({
        @ApiImplicitParam(name = "id", value = "", paramType = "query"),
        @ApiImplicitParam(name = "code", value = "类型编码", paramType = "query")
    })
    @DeleteMapping("/delete")
    @ResponseBody
    public BeanRet delete(java.lang.Long id,java.lang.String code) {
        supplierCategorySV.delete(id,code);
        return BeanRet.create(true, "删除SupplierCategory成功");
    }

}
